<template>
    <dir>
        <van-sticky>
            <van-nav-bar title="投递简历" left-text="返回" left-arrow @click-left="onClickLeft" right-text="首页"
                @click-right="onClickRight" />
        </van-sticky>
        <div class="img">
            <img src="@/assets/投递简历.png" alt="">
        </div>

        <van-form validate-first @failed="onFailed" @submit="onSubmit">
            <!-- 通过 pattern 进行正则校验 -->
            <van-field v-model="money" label="期望薪资" name="money" placeholder="期望薪资" />

            <van-field readonly clickable name="date" :value="value" label="投递日期" placeholder="点击选择日期"
                @click="showCalendar = true" />
            <van-calendar v-model="showCalendar" @confirm="onConfirm" />

            <van-field v-model="message" name="留言" label="留言" placeholder="请输入留言" type="textarea"
                :rules="[{ required: true }]" />
            <div style="margin: 16px;">
                <van-button round block type="info" native-type="submit">投递</van-button>
            </div>
        </van-form>
        <div style="margin: 16px;">
            <van-button round block type="info" @click="gotoDeliverList">查看历史投递列表</van-button>
        </div>
    </dir>
</template>

<script>
import Vue from 'vue';
import nav from "@/mixin/nav";
import { Calendar } from 'vant';
Vue.use(Calendar);
import { deliver } from "@/service/job/jobservice";
import { Toast } from 'vant';

Vue.use(Toast);
export default {
    mixins: [nav],
    data() {
        return {

            money: "",
            value: '',
            message: "",
            showCalendar: false,
            showPicker: false,
            show: false,
            deliver: {}
        }
    },
    async created() {
        //   this.onSubmit()
    },
    methods: {
        onClickLeft() {
            this.$router.go(-1)
        },
        onClickRight() {
            this.$router.push("/")
        },
        async onSubmit(val) {
            console.log(val.money);
            console.log(this.remark);
            const getNowDate = () => {
                var date = new Date();
                var sign2 = ":";
                var year = date.getFullYear(); // 年
                var month = date.getMonth() + 1; // 月
                var day = date.getDate(); // 日
                var hour = date.getHours(); // 时
                var minutes = date.getMinutes(); // 分
                var seconds = date.getSeconds(); //秒
                // 给一位数的数据前面加 “0”
                if (month >= 1 && month <= 9) {
                    month = "0" + month;
                }
                if (day >= 0 && day <= 9) {
                    day = "0" + day;
                }
                if (hour >= 0 && hour <= 9) {
                    hour = "0" + hour;
                }
                if (minutes >= 0 && minutes <= 9) {
                    minutes = "0" + minutes;
                }
                if (seconds >= 0 && seconds <= 9) {
                    seconds = "0" + seconds;
                }
                return (
                    year +
                    "-" +
                    month +
                    "-" +
                    day +
                    " " +
                    hour +
                    sign2 +
                    minutes +
                    sign2 +
                    seconds
                );
            };

            this.companyId = this.$route.params.companyId;
            this.postId = this.$route.params.professionId;
            this.postName = this.$route.params.name;
            this.satrTime = getNowDate();
            this.money = val.money;
            this.remark = val.message;
            // console.log(this.companyId);
            let params = {
                companyId: this.companyId,
                postId: this.postId,
                postName: this.postName,
                satrTime: this.satrTime,
                money: this.money,
                remark: this.remark

            }
            console.log(params);

            let { data } = await deliver(params)
            console.log(data);
            this.$dialog.confirm({
                title: '投递成功',
                message: '是否跳转历史投递页面',
            }).then(() => {
                this.$router.push("/deliverlist")
            })
                .catch(() => {
                });
        },
        onFailed() {
            Toast('请输入完整参数');
        },
        onConfirm(date, value) {
            this.showCalendar = false;
            this.value = value;
            this.show = false;
            this.value = `${date.getMonth() + 1}/${date.getDate()}`;
        },
        gotoDeliverList() {
            this.$router.push({
                path: "/deliverlist"
            })
        }

    }
}
</script>

<style lang="scss" scoped>
.img {
    width: 100%;

    img {
        width: 100%;
    }
}
</style>